//
//  TabButton.swift
//  Slide_Menu_Animation
//
//  Created by qingzhou on 2021/5/12.
//

import SwiftUI

struct TabButton: View {
    var title: String
    var image: String
    
    @Binding var seletedTab: String
    var animation: Namespace.ID
    var body: some View {
        Button(action:{
            withAnimation(.spring()) {
                seletedTab = title
            }
        }) {
            HStack(spacing: 10) {
                Image(systemName: image)
                    .font(.title2)
                    .frame(width:30)
                Text(title)
                    .fontWeight(.semibold)
            }
            .foregroundColor(seletedTab == title ? Color.blue : .white)
            .padding(.vertical, 12)
            .padding(.horizontal, 20)
            .frame(maxWidth: getRect().width - 170, alignment: .leading)
            .background(
                
                ZStack {
                    if seletedTab == title {
                    Color.white
                        .opacity(seletedTab == title ? 1 : 0)
                        .clipShape(CustomShape(corners: [.topRight, .bottomRight], radius: 12))
                        .matchedGeometryEffect(id: "TAB", in: animation)
                    }
                    
                }
               
            )
        }
    }
}

struct TabButton_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
